<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty text modifier plugin
 *
 * Type:     modifier<br>
 * Name:     text<br>
 * Purpose:  Replace all repeated spaces, newlines, tabs
 *           with a single space or supplied replacement string.<br>
 * Example:  {$var|text} {$var|text:"&nbsp;"}
 * Date:     September 25th, 2002
 * @link http://smarty.php.net/manual/en/language.modifier.text.php
 *          text (Smarty online manual)
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @version  1.0
 * @param string
 * @param string
 * @return string
 */
function smarty_modifier_text($text, $type = '', $param = '')
{
  //
  $text = str_replace(array('\r\n', '\n', '\r'), array("\r\n", "\n", "\r"), $text);
  //
  if( $param == 'html' ) {
  	$text = htmlspecialchars($text);
  } elseif( $param == 'htmlspecialchars' ) {
  	$text = htmlspecialchars($text, ENT_QUOTES);
  } elseif( $param == 'htmlspecialchars-quotes' ) {
  	$text = htmlspecialchars($text, ENT_QUOTES);
  } elseif( $param == 'htmlspecialchars-compat' ) {
  	$text = htmlspecialchars($text, ENT_COMPAT);
  } elseif( $param == 'htmlentities' ) {
  	$text = htmlentities($text, ENT_QUOTES);
  } elseif( $param == 'htmlentities-quotes' ) {
  	$text = htmlentities($text, ENT_QUOTES);
  } elseif( $param == 'htmlentities-compat' ) {
  	$text = htmlentities($text, ENT_COMPAT);
  } elseif( $param == 'strip_tags' ) {
  	$text = strip_tags($text);
  } elseif( $param == 'addslashes' ) {
  	$text = addslashes($text);
  } elseif( $param == 'stripslashes' ) {
  	$text = stripslashes($text);
  } else {
	$text = htmlspecialchars(stripslashes($text));
  }
  //
  if( $type == 'break' ) {
    $text = util_string_break($text, 60, '<br>');
  } elseif( $type == 'nl2br' ) {
    $text = nl2br($text);
  } elseif( $type == 'html' ) {
	$text = htmlspecialchars($text);
  } elseif( $type == 'htmlspecialchars' ) {
	$text = htmlspecialchars($text);
  } elseif( $type == 'htmlentities' ) {
	$text = htmlentities($text);
  } elseif( $type == 'htmlentities-quote' ) {
	$text = htmlentities($text, ENT_COMPAT);
  } elseif( $type == 'htmlentities-quotes' ) {
	$text = htmlentities($text, ENT_QUOTES);
  } elseif( $type == 'strip_tags' ) {
	$text = strip_tags($text);
  } elseif( $type == 'addslashes' ) {
  	$text = addslashes($text);
  } elseif( $type == 'stripslashes' ) {
  	$text = stripslashes($text);
  }
  
  return $text;
}

/* vim: set expandtab: */

?>
